<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection"
	content="telephone=no,email=no,date=no,address=no">
<title></title>
<link rel="stylesheet" type="text/css" href="../css/aui.css" />
<link rel="stylesheet" type="text/css"
	href="../css/aui-pull-refresh.css" />
<style type="text/css">
.aui-list .aui-list-item i.aui-iconfont {
	-webkit-align-self: center;
	align-self: center;
	font-size: 18px;
}
</style>
</head>
<body>
	<header class="aui-bar aui-bar-nav aui-bar-warning" id="aui-header">
	<a class="aui-pull-left" onclick="window.history.back(-1);"> <span
		class="aui-iconfont aui-icon-left"></span>
	</a>
	<div class="aui-title">修改资料</div>
	<a class="aui-pull-right"> </a> </header>

	<section class="aui-content">
	<form id="myFrom" enctype ="multipart/form-data">
		<ul class="aui-list aui-list-in aui-margin-b-15">
			<li class="aui-list-item aui-list-item-middle">
				<div class="aui-list-item-label">头像:</div>
				<div class="aui-list-item-inner" style="width: inherit;"
					onclick="loadAvatar()">
					
					<label for="hotelImgFile">
					<div class="aui-list-item-media" style="width: 3.5rem;">
						<img src="../../img/bing.png"
							class="aui-img-round aui-list-img-sm" id="picture1"> 
							 	<input type="hidden" name="picture" id="picture" />
					</div>
					<input type="file" id="hotelImgFile" name="hotelImgFile" style="display: none" />
					</label>
					
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label">姓名:</div>
				<div class="aui-list-item-inner">
					<input type="text" class="input-class" placeholder="请输入姓名"
						id="name" name="name"> <input type="hidden"
						id="employeeId" name="employeeId">
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label ">性别:</div>
				<div class="aui-list-item-inner aui-list-item-input" id="sex"></div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label">生日:</div>
				<div class="aui-list-item-inner aui-list-item-input" id="birthday"></div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label">所在部门:</div>
				<div class="aui-list-item-inner aui-list-item-input" id="deptName"></div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label">职务:</div>
				<div class="aui-list-item-inner aui-list-item-input" id="position"></div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label">联系手机:</div>
				<div class="aui-list-item-inner">
					<input type="text" class="input-class" placeholder="请输入手机号"
						id="phoneNumber" name="phoneNumber">
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label">邮箱地址:</div>
				<div class="aui-list-item-inner">
					<input type="text" class="input-class" placeholder="请输入邮箱"
						id="email" name="email">
				</div>
			</li>
			<li class="aui-list-item">
				<div class="aui-list-item-label">联系地址:</div>
				<div class="aui-list-item-inner">
					<input type="text" class="input-class" placeholder="请输入电话"
						id="address" name="address">
				</div>
			</li>
		</ul>
		<div class="aui-btn aui-btn-primary aui-btn-block"
			onclick="submitCustomer()" style="margin: 0 auto;width: 95%;">
			提交</div>
	</form>
	</section>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
	//初始方法
	$(function(){
		 	getPage();
			//选择头像之后的事件
			$("#hotelImgFile").change(function(){
				var file=$("#hotelImgFile");
				var suffix=file.val().substring(file.val().lastIndexOf(".")+1,file.val().length);
				var picture=file.val().substring(file.val().lastIndexOf("\\")+1,file.val().length);
				var imageSize=file[0].files[0].size/1024;//kb
				//JPG,JPEG,PNG,BMP,GIF格式
				if(suffix!="jpg"&&suffix!="jpeg"&&suffix!="png"&&suffix!="bmp"&&suffix!="gif"){
					file.val("");//清空
					sweetAlert("提示", "仅支持10M以下JPG,JPEG,PNG,BMP,GIF格式图片!", "error");
				}else if(imageSize>1024*5){  //仅支持5M内的图片
					file.val("");//清空
					sweetAlert("提示", "图片文件的大小不能超过5M!", "error");
				}else{
					$("#picture").val(file.val());
				}		
			});
		});

	function getPage() {
		$.ajax({
					url : '${pageContext.request.contextPath}/appcrm/cardDetail.do?',
					type : "POST",
					dataType : "json",
					success : function(data) {
						if (data.code == "0") {
							if (data.emp != "undefined") {
								$("#employeeId").val(data.emp.employeeId);
								$("#sex").html(data.emp.sex);
								$("#birthday").html(toDate(data.emp.birthday));
								$("#position").html(data.emp.position);
								$("#deptName").html(data.emp.dept.deptName);
								if (data.emp.email != "") {
									$("#email").val(data.emp.email);
									$("#email").attr("placeholder", "");
								}
								if (data.emp.address != "") {
									$("#address").val(data.emp.address);
									$("#address").attr("placeholder", "");
								}
								if (data.emp.phoneNumber != "") {
									$("#phoneNumber").val(data.emp.phoneNumber);
									$("#phoneNumber").attr("placeholder", "");
								}
								if (data.emp.name != "") {
									$("#name").val(data.emp.name);
									$("#name").attr("placeholder", "");
								}
								if (data.emp.picture != "" && data.emp.picture != null) {
									$("#picture1").attr("src", '${pageContext.request.contextPath}/'+ data.emp.picture);
									$("#picture").val(data.emp.picture);
								}
							}
						}
					}
				});
	}
	


	function submitCustomer() {
		var name = $("#name").val().trim();
		var phoneNumber = $("#phoneNumber").val().trim();
		var email = $("#email").val().trim();
		var address = $("#address").val().trim();

		if (name == "") {
			showMsg("请填写姓名!");
			return false;
		}
		if (phoneNumber == "") {
			showMsg("请填写手机号码!");
			return false;
		}
		if (email == "") {
			showMsg("请填写邮箱!");
			return false;
		}
		var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (reg.test(email)) {
				jQuery("#email").val(email);
			} else {
				jQuery("#email").val("");
				showMsg("您输入的邮箱格式有误!");
				return false;
			}

		/**
		{
				"employeeId" : $("#employeeId").val(),
				"name" : $("#name").val(),
				"picture" : $("#picture").val(),
				"phoneNumber" : $("#phoneNumber").val(),
				"email" : $("#email").val(),
				"address" : $("#address").val(),
				"hotelImgFile" :formData
			}
		*/
		var formData = new FormData  ($("form")[0]);
		$.ajax({
			url : '${pageContext.request.contextPath}/appcrm/modify_weixin.do',
			type : "POST",
			data : formData,
		     data:formData,
		     cache:false,
		     contentType: false,
		     processData: false,
			success : function(data) {
				if (data.code == 0) {
					showMsg("提交成功");
				} else {
					showMsg("提交失败");
				}
				setTimeout(function() { 
				window.location.href=window.location.href;
				window.location.reload;
				}, 1000);
				

			}
			
		});
	}

	function toDate(data) {
		var date = new Date(data);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		m = m < 10 ? '0' + m : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		return y + '-' + m + '-' + d;
	}
	/**
	 *转换金钱100,000.00 
	 */
	function formatCurrency(num) {
		if (num != null && num != "") {
			num = num.toString().replace(/\$|\,/g, '');
			if (isNaN(num))
				num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num * 100 + 0.50000000001);
			cents = num % 100;
			num = Math.floor(num / 100).toString();
			if (cents < 10)
				cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
				num = num.substring(0, num.length - (4 * i + 3)) + ','
						+ num.substring(num.length - (4 * i + 3));
			return (((sign) ? '' : '-') + num + '.' + cents);
		}
	}
</script>
</html>